From 840f138cfaa1a591ebf3bc330e29aa872340443a Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Sun, 10 Jun 2007 19:58:22 +0100 Subject: [PATCH] tools: Fix xenstored build error by checking vasprintf() return code. Signed-off-by: Charles Coffing --- tools/xenstore/utils.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/xenstore/utils.c b/tools/xenstore/utils.c index 6655777bcd..16f87cdc05 100644 --- a/tools/xenstore/utils.c +++ b/tools/xenstore/utils.c @@ -27,33 +27,38 @@ void xprintf(const char *fmt, ...) void barf(const char *fmt, ...) { char *str; + int bytes; va_list arglist; xprintf("FATAL: "); va_start(arglist, fmt); - vasprintf(&str, fmt, arglist); + bytes = vasprintf(&str, fmt, arglist); va_end(arglist); - xprintf("%s\n", str); - free(str); + if (bytes >= 0) { + xprintf("%s\n", str); + free(str); + } exit(1); } void barf_perror(const char *fmt, ...) { char *str; - int err = errno; + int bytes, err = errno; va_list arglist; xprintf("FATAL: "); va_start(arglist, fmt); - vasprintf(&str, fmt, arglist); + bytes = vasprintf(&str, fmt, arglist); va_end(arglist); - xprintf("%s: %s\n", str, strerror(err)); - free(str); + if (bytes >= 0) { + xprintf("%s: %s\n", str, strerror(err)); + free(str); + } exit(1); } -- 2.30.2